package com.kefu.admin.config;

import com.kefu.admin.modules.tgqmdj.service.TgdService;
import com.kefu.admin.modules.tgqmdj.service.impl.TgdServiceImpl;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.beanutils.converters.DateConverter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class StartedEventListener implements ApplicationListener<ContextRefreshedEvent> {

    private static final Logger logger = LoggerFactory.getLogger(StartedEventListener.class);


    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        ConvertUtils.register(new DateConverter(null), Date.class);
        if(AppDataContext.getContext() == null){
            AppDataContext.setApplicationContext(event.getApplicationContext());
            TgdService tgdService = AppDataContext.getContext().getBean(TgdServiceImpl.class);
            tgdService.initCommtable();
            logger.info("StartedEventListener OK");


        }
    }
}
